<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>发布</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<link href="css/mui.picker.css" rel="stylesheet" />
		<link href="css/mui.poppicker.css" rel="stylesheet" />
		<style type="text/css">
			html {
				font-size: 16px;
			}

			#app {
				padding-top: 44px;
			}

			.mui-input-group .mui-input-row {
				height: auto;
				padding: 0.5rem 0;
				font-size: 0.9375rem;
			}

			.mui-input-group .mui-input-row input {
				font-size: 0.9375rem;
				color: #333333;
			}

			.mui-input-group .mui-input-row:after {
				right: 15px;
			}

			.mui-input-group:before,
			.mui-input-group::after {
				display: none;
			}

			.mui-input-row label {
				line-height: 18px;
				color: #333333;
			}

			::-webkit-input-placeholder {
				/* WebKit browsers */
				color: #CCCCCC;
				font-size: 0.9375rem;
			}

			::-moz-placeholder {
				/* Mozilla Firefox 19+ */
				color: #CCCCCC;
				font-size: 0.9375rem;
			}

			:-ms-input-placeholder {
				/* Internet Explorer 10+ */
				color: #CCCCCC;
				font-size: 0.9375rem;
			}

			.uploadImg {
				position: relative;
				float: left;
			}

			.uploadImg img {
				width: 6.125rem;
				height: 6.125rem;
			}

			.uploadImg input {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				opacity: 0;
			}

			.mui-input-row:last-child::after {
				display: none;
			}

			.submit {
				width: 3.5625rem;
				height: 32px;
				line-height: 32px;
				text-align: center;
				color: white;
				font-size: 0.8125rem;
				background: linear-gradient(180deg, #FF8E3C 0%, #FC6A02 100%);
				opacity: 0.6;
				padding: 0;
				margin: 0 auto;
				border: none;
				border-radius: 2px;
				margin-top: 6px;
			}
			.submit.active{
				opacity: 1;
			}

			.uploadImgList {
				float: left;
			}

			.uploadImgList .item {
				width: 6.125rem;
				height: 6.125rem;
				position: relative;
				margin-right: 0.625rem;
				float: left;
			}

			.uploadImgList .item img,.uploadImgList .item video {
				width: 100%;
				height: 100%;
			}

			textarea {
				padding: 10px 15px;
				line-height: 1.125rem;
				font-size: 0.875rem;
				height: 6.875rem;
			}
			.uploadImgList .item .close{
				position: absolute;
				top: 0;
				right: 0;
				width: 1.5rem;
				height: 1.5rem;
			}
			
			
			/* 图片预览代码 */
			.mui-preview-image.mui-fullscreen {
				position: fixed;
				z-index: 20;
				background-color: #000;
			}
			.mui-preview-header,
			.mui-preview-footer {
				position: absolute;
				width: 100%;
				left: 0;
				z-index: 10;
			}
			.mui-preview-header {
				height: 44px;
				top: 0;
			}
			.mui-preview-footer {
				height: 50px;
				bottom: 0px;
			}
			.mui-preview-header .mui-preview-indicator {
				display: block;
				line-height: 25px;
				color: #fff;
				text-align: center;
				margin: 15px auto 4;
				width: 70px;
				background-color: rgba(0, 0, 0, 0.4);
				border-radius: 12px;
				font-size: 16px;
			}
			.mui-preview-image {
				display: none;
				-webkit-animation-duration: 0.5s;
				animation-duration: 0.5s;
				-webkit-animation-fill-mode: both;
				animation-fill-mode: both;
			}
			.mui-preview-image.mui-preview-in {
				-webkit-animation-name: fadeIn;
				animation-name: fadeIn;
			}
			.mui-preview-image.mui-preview-out {
				background: none;
				-webkit-animation-name: fadeOut;
				animation-name: fadeOut;
			}
			.mui-preview-image.mui-preview-out .mui-preview-header,
			.mui-preview-image.mui-preview-out .mui-preview-footer {
				display: none;
			}
			.mui-zoom-scroller {
				position: absolute;
				display: -webkit-box;
				display: -webkit-flex;
				display: flex;
				-webkit-box-align: center;
				-webkit-align-items: center;
				align-items: center;
				-webkit-box-pack: center;
				-webkit-justify-content: center;
				justify-content: center;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				width: 100%;
				height: 100%;
				margin: 0;
				-webkit-backface-visibility: hidden;
			}
			.mui-zoom {
				-webkit-transform-style: preserve-3d;
				transform-style: preserve-3d;
			}
			.mui-slider .mui-slider-group .mui-slider-item img {
				width: auto;
				height: auto;
				max-width: 100%;
				max-height: 100%;
			}
			.mui-android-4-1 .mui-slider .mui-slider-group .mui-slider-item img {
				width: 100%;
			}
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-slider-group .mui-slider-item {
				display: inline-table;
			}
			.mui-android-4-1 .mui-slider.mui-preview-image .mui-zoom-scroller img {
				display: table-cell;
				vertical-align: middle;
			}
			.mui-preview-loading {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				display: none;
			}
			.mui-preview-loading.mui-active {
				display: block;
			}
			.mui-preview-loading .mui-spinner-white {
				position: absolute;
				top: 50%;
				left: 50%;
				margin-left: -25px;
				margin-top: -25px;
				height: 50px;
				width: 50px;
			}
			.mui-preview-image img.mui-transitioning {
				-webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
				transition: transform 0.5s ease, opacity 0.5s ease;
			}
			@-webkit-keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			@keyframes fadeIn {
				0% {
					opacity: 0;
				}
				100% {
					opacity: 1;
				}
			}
			@-webkit-keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			@keyframes fadeOut {
				0% {
					opacity: 1;
				}
				100% {
					opacity: 0;
				}
			}
			p img {
				max-width: 100%;
				height: auto;
			}
		</style>
	</head>

	<body style="background-color: #FFFFFF;">
		<div id="app">
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-closeempty mui-pull-left"></a>
				<h1 class="mui-title">发布</h1>
				<!-- <a class="mui-btn ">111</a> -->
				<button type="button" class="submit mui-pull-right" :class="canLogin?'active':''" @click="submit">发布</button>
			</header>

			<div class="list">
				<form class="mui-input-group">
					<!-- <div class="mui-input-row">
						<a class="mui-navigate-right">
							<label>新闻类型</label>
							<input type="text" v-model="typeName" placeholder="请选择新闻类型" readonly id='showCityPicker'>
						</a>
					</div> -->
					<div class="mui-input-row">
						<label>标题内容</label>
						<input type="text" placeholder="请输入标题内容" v-model="title">
					</div>
					<div class="mui-input-row">
						<textarea id="textarea" rows="5" placeholder="内容描述…" v-model="content"></textarea>
					</div>
					<div class="mui-input-row clearfix" style="padding-left: 15px;padding-top: 1.25rem;">
						<div class="uploadImgList clearfix">
							<div class="item" v-for="item,index in fileList">
								<template v-if="item.type == 1">
									<img :src="baseUrl + item.src" data-preview-src="" data-preview-group="1">
								</template>
								<template v-else>
									<video :src="baseUrl + item.src"></video>
								</template>
								<img src="images/close.png" class="close" @click="deleteImg(index)">
							</div>
						</div>
						<div class="uploadImg">
							<img src="images/upLoad.png">
							<input type="file" @change="chooseImg" id="uploadInput" />
						</div>
					</div>
				</form>
			</div>
		</div>

		<script src="js/mui.js"></script>
		<script src="js/vue.js"></script>
		<script src="js/mui.picker.js"></script>
		<script src="js/mui.poppicker.js"></script>
		<script src="js/mui.zoom.js"></script>
		<script src="js/mui.previewimage.js"></script>
		<script type="text/javascript">
			var app = new Vue({
				el: '#app',
				data: {
					fileList: [],
					typeName: "",
					type: "",
					typeList: [{
							value: '0',
							text: '社会新闻'
						}, {
							value: '1',
							text: '电力新闻'
						}, {
							value: '2',
							text: '部门投稿'
						}, {
							value: '3',
							text: '本地新闻'
						},
						{
							value: '4',
							text: '线索汇总'
						}
					],
					title: "",
					content: "",
					userinfo: {},
					baseUrl:baseUrl,
				},
				methods: {
					deleteImg:function(index){
						this.fileList.splice(index,1)
					},
					chooseImg: function(event) {
						var file = event.target.files[0];
						var fileType = 0;
						if(file.type.indexOf("image") > -1){
							fileType = 1
						}else if(file.type.indexOf("video") > -1){
							fileType = 2;
						}else{
							mui.toast("文件格式不支持！", {
								duration: 'short',
								type: 'div'
							})
							document.getElementById('uploadInput').value = ""
							return
						}
						console.log(file)
						mui.showLoading("正在上传..","div")
						$uploadFile(file, function(res) {
							app.fileList.push({src:res,type:fileType});
							mui.hideLoading()
							app.$nextTick(function(){
								mui.previewImage();
								document.getElementById('uploadInput').value = ""
							})
						})
					},
					initPicker: function() {
						var cityPicker = new mui.PopPicker({
							layer: 1
						});
						cityPicker.setData(this.typeList);
						var showCityPickerButton = document.getElementById('showCityPicker');
						showCityPickerButton.addEventListener('tap', function(event) {
							cityPicker.show(function(items) {
								app.typeName = items[0].text;
								app.type = items[0].value;
							});
						}, false);
					},
					submit: function() {
						var imagesList = [];
						var videofileList = [];
						this.fileList.forEach(function(item){
							(item.type == 1?imagesList:videofileList).push(item.src)
						})
						var params = {
							type: 4,
							title: this.title,
							content: this.content,
							department_id: this.userinfo.department_id,
							user_id: this.userinfo.user_id,
							images:imagesList.toString(),
							videofile:videofileList.toString(),
						}
						$post("/api/news/release",params,function(res){
							mui.toast("新闻发布成功！", {
								duration: 'short',
								type: 'div'
							})
							setTimeout(function(){
								mui.openWindow("list_02.html")
							},2000)
						})
						console.log(params)
					},
				},
				computed: {
					canLogin: function() {
						return this.type && this.title && this.content
					}
				},
				created: function() {

				},
				mounted: function() {
					this.initPicker()
					mui.init()
					if (localStorage.getItem("userinfo")) {
						this.userinfo = JSON.parse(localStorage.getItem("userinfo"))
					}
				}
			})
		</script>
	</body>

</html>
